package com.frx.leetoffer.dayone;

/**
 * Created with IDEA
 *  找出数组中重复的数字
 * @author: xrf
 * @Date: 2019/11/17
 * @Time: 10:34
 */
public class ArrayRepeatTest {

    public static void main(String[] args){
        int[] arr = {3,5,6,4,4,0,0,2,1};
        int[] res = new int[2];
        if (isRepeat(arr,res)){
            System.out.println(res[0]);
        }

    }

    public static boolean isRepeat(int[] arr,int[] res){
        for (int i=0;i<arr.length;i++){
            while (i != arr[i]){
                if (arr[i] == arr[arr[i]]){
                    res[0] = arr[i];
                    return true;
                }
                if (i != arr[i]){
                    int j = arr[i];
                    int tmp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = tmp;
                }
            }

        }

        return false;
    }

}
